package hw;

public class DumplingTest {
    public static void main(String[] args) {
        Thread t1 = new Thread(new getNum(3000), "大壮");
        Thread t2 = new Thread(new getNum(5000), "小明");
        t1.start();
        t2.start();
    }
}

class getNum implements Runnable {
    /**
     * 大壮吃的饺子个数
     */
    private int count1;
    /**
     * 小明吃的饺子个数
     */
    private int count2;
    /**
     * 饺子总个数
     */
    public static int dumpling = 25;
    /**
     * 吃饺子花的时间（休眠时间）
     */
    private int time;

    public getNum(int time) {
        this.time = time;
    }

    @Override
    public void run() {
        while (dumpling > 0) {
            if (Thread.currentThread().getName().equals("大壮")) {
                count1++;
                System.out.println("大壮吃了" + count1 + "个饺子");
            } else {
                count2++;
                System.out.println("小明吃了" + count2 + "个饺子");
            }
            dumpling--;
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
